// Have include guard.
#ifndef ASYNCRESULTEFFECTSTATE_H
#define ASYNCRESULTEFFECTSTATE_H

#include "ChainState.hpp"

template<typename Result>
class AsyncResultStartState;

/**
 *  The AsyncResultStartState class is a state that starts and finishes an async operation that uses an AsyncResult.
 *  
 *  This class is untested.
 */
template<typename Result>
class AsyncResultEffectState :
	public ChainState
{
	private:
		typedef typename AsyncResultStartState<Result>::FinishState FinishState; 
		
		AsyncResultStartState<Result> *m_stateStart;
		FinishState *m_stateFinish;
	public:
		AsyncResultEffectState() :
			m_stateStart(NULL),
			m_stateFinish(NULL)
		{		
		}
		
		virtual ~AsyncResultEffectState()
		{
			if (m_stateFinish != NULL)
				delete m_stateFinish;
		}
	protected:
		void SetStartState(AsyncResultStartState<Result> &startState)
		{
			m_stateStart = &startState;
			m_stateFinish = new FinishState(*m_stateStart);
			AppendState(*m_stateStart);
			AppendState(*m_stateFinish);
		}
		
		/**
		 *  Adds a mapping to map a result from the async operation to a StateDoneCode.
		 *  
		 *  @param result The result to map from.
		 *  @param doneCode The StateDoneCode to transition to.
		 */
		void AddResultDoneCodeMapping(Result result, StateDoneCode doneCode)
		{
			m_stateFinish->AddResultDoneCodeMapping(result, doneCode);
		}
};

#endif // #ifndef ASYNCRESULTEFFECTSTATE_H
